<!-- *Author: 黄旗, *Date: 2020-08-04 15:45:59 -->
<template>
<div>
    <Modal v-model='modal' title='上传站点' :mask-closable='false' @on-cancel='canceledit(modalname)' draggable>
        <Form :label-width='120' :ref='modalname' :model='modalparams' :rules='createRules'>
            <FormItem label='上传类型：'>
                <RadioGroup v-model="modalparams.upload_type">
                    <Radio label="1">按日期上传</Radio>
                    <Radio label="2">整站上传</Radio>
                </RadioGroup>
            </FormItem>
            <FormItem label='选择时间：' v-if="modalparams.upload_type == 1">
                <!-- <DatePicker :clearable="false" v-model="modalparams.edit_file_time" placeholder="请选择时间" style="width: 200px"></DatePicker> -->
                <DatePicker type="daterange"  placeholder="请选择时间" v-model="modalparams.edit_file_time" style="width: 200px"></DatePicker>
            </FormItem>
            <FormItem label='上传方式：'>
                <RadioGroup v-model="modalparams.way_type">
                    <Radio label="1">直接上传</Radio>
                    <Radio label="2">后台上传</Radio>
                </RadioGroup>
            </FormItem>
            <p class="red" style="margin-left:35px">说明：站点过大或整站上传，建议选择“后台上传”</p>

        </Form>
        <div slot='footer'>
            <Button @click='canceledit(modalname)'>取消</Button>
            <Button type='primary' :loading="subloading" @click='submitedit(modalname)'>{{subloading?'正在上传':'开始上传'}}</Button>
        </div>
    </Modal>
    <Modal v-model="modalcon">
        <p class="ivu-mt-16">队列中已有当前任务在执行，此次上传将会添加一条新队列任务，不会被立即执行！</p>
        <p> 队列中任务未完成之前，请勿重复上传。</p>
         <div slot='footer'>
            <!-- <Button @click='canceleis_wait_queue()'>取消</Button> -->
            <Button type='primary' :loading="subloading" @click='submitis_wait_queue()'>确定</Button>
        </div>
    </Modal>
    <Modal v-model="modalStatus">
        <p class="ivu-mt-16">请记得同步更新上传当前站点对应的手机/PC站点</p>
        <div v-for="(item,index) in list" :key="index">
            <P>{{item}}</P>
        </div>
         <div slot='footer'>
            <!-- <Button @click='canceleis_wait_queue()'>取消</Button> -->
            <Button type='primary' @click='onOk'>确定</Button>
        </div>
    </Modal>
</div>
</template>

<script>
    import { siteindexupload, getcommonList } from '@api/httpsetting'
import PablishAartice from '../release/pablishAartice/index.vue';
    export default {
        name: '',
        components: { PablishAartice },
        data () {
            return {
                modalname: 'modalname',
                subloading: false,
                modal: false,
                modalparams: { id: '', upload_type: '1', edit_file_time: [new Date(), new Date()], way_type: '1' },
                createRules: {
                    edit_file_time: [{
                        required: true,
                        message: '请选择时间',
                        trigger: 'change'
                    }]
                },
                db_type: '',
                commonList: [],
                modalcon:false,
                modalStatus:false,
                list:[]
            };
        },
        /* 函数方法集合 */
        methods: {
            /* @函数功能: 初始化 */
            initial (row) {
                this.db_type = row.db_type
                this.modalparams = { id: row.id, upload_type: '1', edit_file_time: [new Date(), new Date()], way_type: '1' },
                this.modal = true
            },
            askData () {
            }, // 请求数据处理
            canceledit () {
                this.modal = false
            },
            submitedit () {
                this.subloading = true
                let params = {
                    id: this.modalparams.id,
                    upload_type: this.modalparams.upload_type,
                    start_edit_file_time: this.$Date(this.modalparams.edit_file_time[0]).format('YYYY-MM-DD'),
                    end_edit_file_time: this.$Date(this.modalparams.edit_file_time[1]).format('YYYY-MM-DD'),
                    way_type: this.modalparams.way_type
                }
                siteindexupload(params).then(res => {
                    this.subloading = false
                    this.$Message.success('上传成功')
                    this.list=res.list
                    // let arr=[]
                    // arr= res.list.forEach((t, i) => {if(i > 0 && i % 10 === 0) res.list.splice(i, 0, '</br>')});
                    // this.list= arr.join(' ');
                    // console.log(arr,'arr')
                    this.modal = false
                    if(+res.is_wait_queue===1){
                        this.modalcon=true
                    }else{
                        this.submitis_wait_queue()
                    }
                       
                    
                   
                }).catch(() => {
                    this.subloading = false
                })
            },
            submitis_wait_queue(){
                this.getdata()
            },
            getdata(){
                if (this.list.length > 0) {
                    this.modalStatus=true 
                }  
            },
            onOk(){
                 this.modalStatus=false 
                this.modalcon=false
                this.$emit('askData')
            }
        }
    }
</script>
   